package com.app.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.ClassmateListActivity;
import com.app.R;
import com.app.bean.ClassmateListBean;

import java.util.ArrayList;
import java.util.List;

public class ClassmateListAdapter extends BaseAdapter {

    List<ClassmateListBean.ListBean> list;

    public ClassmateListAdapter(ClassmateListActivity classmateListActivity, ArrayList<ClassmateListBean.ListBean> listBean) {
        this.list = listBean;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return list.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView==null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_classmate,null);
            holder = new Holder();
            holder.ivHead = convertView.findViewById(R.id.iv_head);
            holder.tvName = convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        }else{
            holder = (Holder) convertView.getTag();
        }
        holder.tvName.setText(list.get(position).getName());
        return convertView;
    }

    class Holder{
        ImageView ivHead;
        TextView tvName;
    }

}
